package cn.org.rookie.jeesdp.core.mongodb;

import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

/**
 * @author LHT
 */

public class QueryBuilder {

    private final Criteria criteria;

    private QueryBuilder(String key, Object value) {
        criteria = new Criteria(key).is(value);
    }

    public static QueryBuilder where(String key, Object value) {
        return new QueryBuilder(key, value);
    }

    public QueryBuilder and(String key, Object value) {
        if (value != null) {
            criteria.and(key).is(value);
        }
        return this;
    }

    public Query build() {
        return new Query(criteria);
    }
}
